<script>
	$(document).ready(function(){
		$.validator.addMethod("correctDate", function(value, element) { 
			return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value); 
		}, jQuery.format("Please specify the correct date format"));
		
		$.validator.addMethod("validUsername", function(value, element) {
			return this.optional(element) || /^[a-z0-9\-]+$/i.test(value);
		}, "Username must contain only letters, numbers, or dashes.");
		
		$("#batchForm").validate({
			rules : {
				batchDate : { required : true, correctDate : true}
			},
			messages : {
				batchDate : { required : 'Please enter batch date'}
			}
		});
	});
</script>
<?php include './pages/stockMenu.php'; ?>
<div class="mainContent">
	<div class="masterData">
		<h3>Current Batches</h3>
		<?php
			include('./system/dbConnection.php');
			if($result=mysql_query("SELECT * FROM batches")){
				if(mysql_num_rows($result)){			
					echo "<table border = '1px' cellspacing='0' width='100%' class='masterTable'>";
					echo "<tr><th>Batch Date</th><th>Description</th></tr>";
					while($row = mysql_fetch_array($result)){
						echo "<tr>";
						echo "<td>" . $row['batchDate'] . "</td>";
						echo "<td>" . $row['batchDescription'] . "</td>";
						echo "</tr>";
					}
					echo "</table>";
				}else{
					echo "No Data in Database";
				}	
			}?>
	</div>
	<div class="mainForm">
		<form id="batchForm" action="./system/action/addBatches.php" name="addBatches" method="POST">		
			<table id="addBatchForm" class="formTable" width="100%">
				<col width="150px"/>
				<tr>
					<td colspan="2">
						<?php
						if(isset($_SESSION['error']) && $_SESSION['error'] != ""){ ?>
							<div class="error">
								<?php echo $_SESSION['error']; ?>
							</div>
						<?php } else if(isset($_SESSION['success']) && $_SESSION['success'] != ""){?>
							<div class="success">
								<?php echo $_SESSION['success']; ?>
							</div>
						<?php }
						?>
					</td>
				</tr>
				<tr>
					<td>Batch Date <label class="mandatory">*</label></td>
					<td><input id="batchDate" type="text" name="batchDate" class="width_200 datePicker"/></td>
				</tr>
				<tr>
					<td>Batch Description</td>
					<td><textarea name="batchDescription" id="batchDescription" class="width_200"></textarea></td>
				</tr>
				<tr>
					<td></td>
					<td><button type="submit" ><img src="public/images/button-img/add.png"/><span> Add </span></button></td>
				</tr>
			</table>
		</form>
	</div>
</div>
